package com.learn.chain.second.interceptors;

import android.text.TextUtils;

import com.learn.chain.second.Interceptor;
import com.learn.chain.second.Request;
import com.learn.chain.second.Response;


public class NetworkInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) {
        // 处理请求
        Request request = chain.request();
        // 在该拦截器中设置请求头
        if (TextUtils.isEmpty(request.getHeader())) {
            request.setHeader("RetryInterceptor");
        }
        // 处理响应结果
        Response response = chain.proceed(request);
        // 给响应结果设置值
        if (TextUtils.isEmpty(response.getNetworkInterceptor())) {
            response.setNetworkInterceptor("NetworkInterceptor");
        }
        return response;
    }
}
